const jsonwebtoken = require("jsonwebtoken");
const secret = "dhyAdmin666";
const JWT = {
  generate(value, time) {
    return jsonwebtoken.sign(value, secret, { expiresIn: time });
  },
  verify(token) {  //验证token
    try {
      return jsonwebtoken.verify(token, secret); //verify方法可验证token是否有效期
    } catch (e) {  //失效就返回 false
      return false;
    }
  },
};

// 验证
// const token = JWT.generate({name:'admin'},'10s')
// console.log(token);
// console.log(JWT.verify(token));

module.exports = JWT;
